#!usr/bin/python
# -*- coding: UTF-8 -*-

'''
翡波那挈数列的迭代实现
兔子繁殖
    1  2  3  4  5  6  7  8  9  10  11 12
    1  1  2  3  5  8  13 21 34 55  89 144
函数定义
F(n) = 1, n = 1
       1, n = 2
       F(n - 1) + F(n - 2), n > 2
假设我们需要求出20个月后，有多少只兔子(迭代vs递归)
'''

def fab(n):
    n1 = 1
    n2 = 1
    n3 = 1

    if n < 1:
        print('输入有误:')
        return -1

    while (n - 2) > 0:
        n3 = n2 + n1
        n1 = n2
        n2 = n3
        n -= 1

    return n3;

result = fab(20)
if result != -1:
    print('总共有%d对兔子诞生!' % result)


def fab(n):
    if n < 1:
        print('输入有误:')
        return -1
    if n == 1 or n == 2:
        return 1
    else:
        return fab(n - 1) + fab(n - 2)

result = fab(20)
if result != -1:
    print('总共有%d对兔子' % result)



